﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;

namespace YouHP.Pages.IndicatorHistory
{
    public class List : YouHP.Pages.PatientBasePage
    {

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected List<IndicatorHistoryInfo> IndicatorHistoryList;
        protected LabcheckInfo IndicatorData;
        protected int GraphHeight = 0;
        protected int PageCount;
        protected int PageIndex;
        protected int PageSize = 10;
        protected string PagingString = "";
        protected int DataCount = 0;
        protected int YGap = 30;

        protected string GraphPath;

        protected new void HandleCommon()
        {
            this.AddLocation("实验室指标记录", "/IndicatorHistory/Index.aspx");
            this.AddLocation("历史记录", "");
            this.SetTitle("实验室指标历史记录");
        }

        protected new void HandlePost()
        {

        }

        protected new void HandleGet()
        {
            PageIndex = RequestTools.GetQueryInt("page", 1);
            int idcid = RequestTools.GetQueryInt("idcid", 0);

            if (idcid <= 0)
            {
                this.AddErrLine("无效的参数");
                return;
            }

            IndicatorData = LabcheckBLL.Instance.GetLabcheckInfo(idcid);
            if (IndicatorData.Id <= 0)
            {
                this.AddErrLine("无效的参数");
                return;
            }

            //通过指标的纵坐标值计算flash图表高度
            string[] indicatorAixs = IndicatorData.GridValues.Split(';');
            GraphHeight = (indicatorAixs.Length + 2) * YGap;

            IndicatorHistoryList = PatientIndicatorBLL.Instance.GetIndicatorHistoryList(PrData.Id, IndicatorData.Id, PageSize, PageIndex, out DataCount);
            IndicatorHistoryList.Sort(new IndicatorHistoryInfoComparer());
            PageCount = Utils.GetPageCount(DataCount, PageSize);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            PagingString = this.GetPagingString(
                PageIndex,
                PageCount,
                "/IndicatorHistory/List.aspx" + query, "page");

            TempUrl = "/IndicatorHistory/IndicatorAjax.aspx?idcid=" + IndicatorData.Id;
            GraphPath = GetUrl(TempUrl);

        }
    }
}